<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>封装一次函数</title>
  </head>
  <body>
    <button id="btn">一次</button>
    <script>
      let btnEle = document.getElementById('btn')

      function once(callback) {
        let isDo = false
        return function (...arg) {
          if (!isDo) {
            isDo = true
            callback.apply(this, arg)
          }
        }
      }
      btnEle.addEventListener(
        'click',
        once(function (event) {
          console.log('函数执行了')
          console.log(this)
          console.log(event)
        })
      )
    </script>
  </body>
</html>
